TreeAgent

The TreeAgent class represents an agent that operates within a tree world environment. The agent can traverse the tree, track its movement, and visualize its path using a heat map.

Attributes

  • algorithmCallBack: function - Callback function for the agent's algorithm.

Constructor

The constructor initializes an instance of the TreeAgent class with attributes defining the tree world.

__init__(self, world, agentName:str, agentColor:str="blue", startNodeId=None, heatMapView:bool=True, heatMapColor:str="#FFA732", heatGradient:float=0.05)

Usage

The TreeAgent class provides methods to control the agent's movement within a tree world, interact with its environment, and visualize heat maps. It serves as a foundation for implementing agent-based simulations and experiments within defined tree-based environments.
  • Parameters:
    • world ( CreateTreeWorld ): The tree world object in which the agent operates.
    • agentName (str): The name of the agent.
    • agentColor (str, optional): The color of the agent. Defaults to "blue".
    • heatMapView (bool, optional): Whether to enable the heat map view. Defaults to True.
    • heatMapColor (str, optional): The color of the heat map. Defaults to "#FFA732".
    • heatGradient (float, optional): The gradient value for the heat map. Defaults to 0.05.
  • Returns: None
  • Raises: ValueError if rows or columns are out of valid range.

Methods

__str__()

This method provides a string representation of the agent, calling the aboutAgent method internally.

Parameters

  • None

Returns

  • str: A string containing information about the agent.

aboutAgent()

This method returns a detailed description of the agent's attributes, such as agent name, color, world name, world ID, and root node ID, formatted in a table for readability.

Parameters

  • None

Returns

  • str: A string containing information about the agent, including agent name, color, world name, world ID, and root node ID.

summary()

This method provides a summary of the agent's run, including the start time, end time, and the elapsed time of the run. This information is formatted in a table for clarity.

Parameters

  • None

Returns

  • str: A summary of the agent's run, including start time, end time, and elapsed time.

setAlgorithmCallBack(algorithmCallBack: function)

This method sets the callback function that will be executed by the agent. The callback function defines the algorithm the agent will follow while traversing the tree.

Parameters

  • algorithmCallBack (function): The callback function to be set.

Returns

  • None

runAlgorithm()

This method executes the previously set algorithm callback function. It also sets the start time before execution and the end time after execution to track the algorithm's runtime.

Parameters

  • None

Returns

  • None

Raises

  • ValueError: If the algorithm callback function is not set.

getHeatMapColor(value: float)

This method returns the color corresponding to a given value on a heat map. It uses an exponential decay function to map the value to a color, which helps visualize the heat map effectively.

Parameters

  • value (float): The value to map to a color on the heat map.

Returns

  • tuple: The RGB color value for the given value on the heat map.

checkGoalState(node)

This method checks if the specified node is a goal state.

Parameters

  • node (TreeNode): The node to be checked.

Returns

  • bool: True if the node is a goal state, False otherwise.

moveAgent(node, delay: int=1)

This method moves the agent to the specified node after a given delay. It updates the heat map and the agent's current position.

Parameters

  • node (TreeNode): The node to which the agent should be moved.
  • delay (int, optional): The delay (in seconds) before moving to the next node. Defaults to 1 second.

Returns

  • bool: True if the agent was successfully moved to the node, False otherwise.